package edu.aynu.service.impl;

import edu.aynu.entity.Judge;
import edu.aynu.es.EsJudgeDao;
import edu.aynu.service.EsJudgeService;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 28241
 * @Date 2021/5/24 17:23
 */
@Service
public class EsJudgeServiceImpl implements EsJudgeService {

    @Autowired
    private EsJudgeDao esJudgeDao;

    /**
     * 通过关键字在judge索引中查询
     * @param judge
     * @return
     */
    @Override
    public List<Judge> queryBySubject(Judge judge) {
        MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("subject", judge.getSubject());
        List<Judge> judges = new ArrayList<>();
        esJudgeDao.search(matchQueryBuilder).forEach(judgeTemp -> judges.add(judgeTemp));
        return judges;
    }
}
